package com.zzyl.config;

import cn.hutool.json.JSONUtil;
import com.zzyl.service.ResourceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.List;

/**
 * @className: InitConfig
 * @description:
 * @author: InnovatorX
 * @date: 2024/6/6 21:46
 * @Version: 1.0
 */
@Slf4j
@Configuration
public class InitConfig implements InitializingBean {
    @Autowired
    private RedisTemplate<String, String> redisTemplate;
    @Autowired
    private ResourceService resourceService;

    /**
     * 查询所有的按钮资源放入redis
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("正在进行初始化配置");
        List<String> allUsers = resourceService.findAllButResource();
        redisTemplate.opsForValue().set("resource:url", JSONUtil.toJsonStr(allUsers));
    }
}
